<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <script src="/static/web/editormd/lib/jquery.min.js"></script>
    <title>发动态</title>
  </head>
  <body>
    <div id="index">
      <h1>发动态</h1>
      <form>
        <textarea
          name="dynamic"
          id="dynamic"
          style="width:80%"
          rows="10"
        ></textarea>
        <p><input type="button" value="Submit" id="submit" /></p>
      </form>
    </div>
    <script>
      $(function() {
        $('#submit').on('click', function() {
          let dynamic = $('#dynamic').val()
          // AJAX提交JSON:
          var para = {
            content: dynamic
          }
          $.ajax({
            type: 'POST',
            dataType: 'json',
            contentType: 'application/json',
            url: '/api/writeDynamic',
            data: JSON.stringify(para)
          })
            .done(function(r) {
              console.log(r)
              alert(r.message)
            })
            .fail(function(jqXHR, textStatus) {
              // Not 200:
              alert('Error: ' + jqXHR.responseJSON.message)
            })
        })
      })
    </script>
  </body>
</html>
